JQ總務處|如何讓w3schools include HTML能夠讀到JavaScript


Posted by itiswonderfall on 2022-03-01

前言

我把 header 跟 footer 各自獨立成一支檔案,然後再用 w3schools 的 include HTML 引入,但發現有些會吃不到原本寫的 JavaScript ,後來上網找答案看到可以用 jQuery 解決而且目前沒發現任何 bug ,如果你的網站要日後好維護,但又沒有需要寫到 PHP 的話可以試試看。

cover

圖片來源

 


 

jQuery

$('body').on('click','對象',function() {
    事件
});

 

引入 w3.js

也可以引入 w3.js 並使用 w3.includeHTML 在加載 HTML 後進行回調

w3.includeHTML(function() { 
    事件
});

 


 

資料來源

w3school include HTML, javascript not working


#jq #jq總務處 #jquery #javascript #w3schools







Related Posts

每日心得筆記 2020-07-09(四)

每日心得筆記 2020-07-09(四)

關於產品開發,PRD 的作用與內容介紹

關於產品開發,PRD 的作用與內容介紹

[25] 強制轉型 - 隱含的強制轉型、Addition Operator、Strings <> Numbers

[25] 強制轉型 - 隱含的強制轉型、Addition Operator、Strings <> Numbers


Comments